
import { layoutPoints } from '../algorithm/layout.js'
import { isObject } from '../utils/index.js'
import { angleMapFn } from '../algorithm/angle.js'

export const layoutAngles = Object.keys(angleMapFn)
export const _layout = (options, shapes, fn) => {
    let len = shapes.length
    let { layout, width, height, o } = options
    if (layout) {
        let type, angle
        if (isObject(layout)) {
            type = layout.type
            angle = layout.angle
        } else {
            type = layout
        }
        let lps = layoutPoints(type, { width, height, o })
        let shapeObj = shapes[len === 1 ? 0 : (i % len)]

        let { n, a } = shapeObj
        lps.forEach((t, i) => {
            let incFn = angleMapFn[angle]
            let inc = incFn ? incFn(a,i, n) : {}
            fn({
                shape: 'circle',
                ...shapeObj,
                o: t,
                ...inc
            })
        })
    } else {
        shapes.forEach(t => fn(t))
    }
}